<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="800" top="100px" destroy-on-close
		@closed="$emit('closed')">
		<el-form :model="FormData" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px">
			<el-form-item label="具体问题">
			<el-input v-model="FormData.name" type="textarea" placeholder="该类别下的具体问题"
				clearable></el-input>
			</el-form-item>
			<el-form-item label="合格分">
			<el-input-number v-model="FormData.passScore" placeholder="合格分" :min="1"
				controls-position="right" style="width: 90px;" />
			</el-form-item>
			<!-- <el-form-item :label="'巡查类别'+Number(index+1)" prop="" v-for="(item,index) in itemList" :key="index">
				<el-input v-model="item.name" type="textarea" placeholder="该类别下的具体问题" clearable
					style="width:50%;"></el-input>
				<el-input-number v-model="FormData.passScore" placeholder="分值" :min="1" controls-position="right"
					class="u-m-l-20" size="large" />
				<el-button type="danger" icon="el-icon-delete" circle class="u-m-l-20"
					@click="deleteItem(item,index)" />
			</el-form-item> -->
		</el-form>
		<template #footer>
			<el-button @click="visible=false">返 回</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				showAMap: false,
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					show: '查看'
				},
				visible: false,
				isSaveing: false,
				fileurlArr: [],
				//表单数据
				FormData: {
					itemList: [{
						name: '',
						passScore: 0,
					}],
				},
				areaProps: {
					value: 'id',
					label: 'name',
					checkStrictly: false
				},
				//验证规则
				rules: {
					parent: [{
						required: true,
						message: '请选择类别'
					}],
					timeout: [{
						required: true,
						message: '请填写超时'
					}],
					name: [{
						required: true,
						message: '请填写状态说明'
					}],

				},
				userInfo: {},
				addTemplate: {
					name: '',
					passScore: 0,
				},
				classInfo: {},
				ptempInfo: {},
				classList: []
			}
		},
		created() {

		},
		mounted() {},
		methods: {
			handleChange(e) {
				console.log(e)
			},
			//新增等级
			addItem() {
				if (this.itemList.length == 9) {
					this.$message('最多只能新增9级！')
				} else {
					this.itemList.push({
						name: []
					})
				}
			},
			// 删除等级
			deleteItem(item, index) {
				this.itemList.splice(index, 1)
			},
			//显示
			open(mode = 'add') {
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			async submit() {
				var valid = await this.$refs.dialogForm.validate().catch(() => {})
				if (!valid) {
					return false
				}
				this.isSaveing = true
				//let children_t = 0
				let ok = 0
				console.log(ok)
				let data = {
					id:this.FormData.id,
					name: this.FormData.name,
					passScore: this.FormData.passScore,
				}
				const res = await this.$API.api.ptemp.save.post(data)
				if (res.code == 200) {
					this.visible = false;
					this.$emit('success', this.FormData, this.mode)
					this.$message.success("操作成功")
				} else {
					this.$alert(res.message, "提示", {
						type: 'error'
					})
				}

			},
			//表单注入数据
			setData(data) {
				// this.FormData.id = data.id
				// this.FormData.name = data.name
				// this.FormData.name = data.name
				// this.FormData.timeout = data.timeout
				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				//Object.assign(this.FormData, cdata)
				this.FormData = data
			}
		}
	}
</script>

<style>
</style>
